from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone


class Clazz(models.Model):
    name = models.CharField(max_length=50, db_comment='班级名', blank=True, null=True)

    manage_name = models.CharField(max_length=20, db_comment='班主任', blank=True, null=True)

    start_time = models.DateTimeField(db_comment='开班时间', blank=True, null=True)

    duration = models. IntegerField(db_comment='课程学时', blank=True, null=True)

    creator = models.CharField(max_length=50, db_comment= '创建人', blank=True, null=True)

    state = models.BooleanField(db_comment='班级状态', blank=True, null=True)

    create_time = models.DateTimeField(db_comment='添加时间', auto_now_add=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment='修改时间', auto_now=True, blank=True, null=True)

    delete_time = models.DateTimeField(db_comment='删除时间', auto_now=True, blank=True, null=True)

    is_delete = models.BooleanField(db_comment='是否删除', blank=True, null=True, default=False)

    class Meta:
        db_table = 'tb_clazz'


class Role(models.Model):

    name = models.CharField(max_length=50, db_comment='角色名', blank=True, null=True)

    code = models.CharField(max_length=50, db_comment='角色代码', blank=True, null=True)

    descript = models.TextField(db_comment='角色描述', blank=True, null=True)

    state = models.BooleanField(db_comment='状态', blank=True, null=True)

    create_time = models.DateTimeField(db_comment='添加时间', auto_now_add=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment='修改时间', auto_now=True, blank=True, null=True)

    delete_time = models.DateTimeField(db_comment='删除时间', auto_now=True, blank=True, null=True)

    is_delete = models.BooleanField(db_comment='是否删除', blank=True, null=True, default=False)


    class Meta:
        db_table = 'tb_role'


class User(AbstractUser):
    tel = models.CharField(max_length=11, db_comment='手机号', blank=True, null=True)

    name = models.CharField(max_length=20, db_comment='真实姓名', blank=True, null=True)

    delete_time = models.DateTimeField(db_comment='删除时间', auto_now=True, blank=True, null=True)

    is_delete = models.BooleanField(db_comment='是否删除', blank=True, null=True, default=False)

    role = models.ForeignKey(to=Role, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='users')

    clazz = models.ForeignKey(to=Clazz, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='users')


    class Meta:
        swappable = 'AUTH_USER_MODEL'
        db_table = 'auth_user'

